﻿/*
 bbase_macro.h
*/

#ifndef _bbase_macro_h_
#define _bbase_macro_h_

/*code block separator*/
#define bb_public			public:
#define bb_protect			protected:
#define bb_private			private:
#define bb_head
#define bb_body
#define bb_end

#define _____(info)			bb_##info	//5 _ characters info only can be predefined symbol
#define __________(info)	bb_##info	//10 _ characters info only can be predefined symbol
#define ___________(info)				//11 _ characters info can be any symbol
#define ______							//6 _ characters
#define ____________					//12 _ characters

/* memory operation helper */
#define bb_free(x) if( (x) ){ free((x)); (x) = NULL; }
#define bb_delete(x) if( (x) ){ delete (x); (x) = NULL; }
#define bb_release(x,func) if( (x) ) { func((x)); (x) = NULL; }

/* error handle helper */
typedef int (*bb_error_handle)(const char* psz_cond, const char* psz_file, int n_line, void* p_param);
#define bb_exit bb_exit_s(1)
//supported by msvc but not gcc 4.5
//#define bb_exit_s(no) _bb_exit_s(no)##:
#define bb_exit_s(no) _bb_exit_s(no):
#define _bb_exit_s(no) bb_exit_gate_##no

#define bb_error(cond) if(!(cond)){goto _bb_exit_s(1);}
#define bb_error_ex(cond,sentence) if(!(cond)){sentence; goto _bb_exit_s(1);}
#define bb_error_s(cond,s) if(!(cond)){goto _bb_exit_s(s);}
#define bb_error_f(cond,pfn,param) if(!(cond)){if((pfn)){(pfn)(#cond,__FILE__,__LINE__,(void*)param);} goto _bb_exit_s(1); }
#define	bb_error_sf(cond,s,pfn,param) if(!(cond)){if((pfn)){(pfn)(#cond,__FILE__,__LINE__,(void*)param);} goto _bb_exit_s(s); }

#define bb_assert(cond) assert(cond)
#endif

/********************************************************************

bey0ndc0de
2010/11/22
常用宏定义
utf-8--with--sig

********************************************************************/
/* last for linux */
